var ad1_imgs;
$(function () {
    //导入共页面并设置参数
    $("#top-nav-html").load("topnav.html");
    $("#foot-html").load("footfile.html");
    myajax("/getadvertisement.json", "get", {}, function (result) {
        if (result.status == 200) {

            ad1_imgs = result.data[0].img.split("!");
            $(".home-info").css("background-image", "url(" + imgs_path + ad1_imgs[0] + ")");
            $("#ad1-html").html(result.data[0].content);


            mc12rbimg(result.data[1].img);
            $("#ad2-html").html(result.data[1].content);

            var ad3_imgs = result.data[2].img.split("!");
            $("#ad3-img1").attr("src", imgs_path + ad3_imgs[0]);
            $("#ad3-img2").attr("src", imgs_path + ad3_imgs[1]);
            $("#ad3-html").html(result.data[2].content)
        }

    });
    myajax("/gethomenews.json", "get", {}, function (result) {
        if (result.status == 200) {
            var i = 1;
            for (let news of result.data) {
                let ymd = news.newsdate.split("-");
                $("#home-mid-content-3-2-r-news-time-d-" + i).text(ymd[2]);
                $("#home-mid-content-3-2-r-news-time-ym-" + i).text(ymd[0] + "-" + ymd[1]);
                $("#home-mid-content-3-2-r-news-info-t-" + i + ">div").text(news.title);
                $("#home-mid-content-3-2-r-news-info-n-" + i).text(news.summary);
                i++;
            }
        }
    });

});

//广告背景图片定时切换
function mc12rbimg(img) {
    var imgs = img.split("!");
    $(".home-mid-content-1-2-right").css("background-image", "url(" + imgs_path + imgs[0] + ")");
    let i = 1;
    var ref = setInterval(function () {
        $(".home-mid-content-1-2-right").css("background-image", "url(" + imgs_path + imgs[i] + ")");
        i++;
        i = i % imgs.length;
    }, 5000);
}

//广告背景图片点击切换
function changeimg(ob) {
    var id = $(ob).attr("id");
    if (id === "img-1-but") {
        $("#img-1-but").css("background-color", "chocolate");
        $("#img-2-but").css("background-color", "paleturquoise");
        $(".home-info").css("background-image", "url(" + imgs_path + ad1_imgs[0] + ")")
    }
    if (id === "img-2-but") {
        $("#img-2-but").css("background-color", "chocolate");
        $("#img-1-but").css("background-color", "paleturquoise");
        $(".home-info").css("background-image", "url(" + imgs_path + ad1_imgs[1] + ")")
    }
}
